package ac.svn.accesscontrol.manager;

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.HashSet;
import java.util.Set;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import ac.notification.event.INotificationListener;
import ac.notification.event.NotificationEvent;
import ac.notification.manager.NotificationRegistrar;
import ac.svn.accesscontrol.context.Context;
import ac.svn.accesscontrol.context.ContextHandler;
import ac.svn.accesscontrol.context.IContextConstants;
import ac.svn.accesscontrol.controller.ListingController;
import ac.svn.accesscontrol.controller.user.UserContactInformationController;
import ac.svn.accesscontrol.controller.user.UserGroupMembershipController;
import ac.svn.accesscontrol.controller.user.UserInfoEditorStatusController;
import ac.svn.accesscontrol.controller.user.UserLocationAccessController;
import ac.svn.accesscontrol.store.Dictionary;
import ac.svn.accesscontrol.store.IConstants;
import ac.svn.accesscontrol.store.IResources;
import ac.svn.accesscontrol.store.ISVNIdentifier;
import ac.svn.accesscontrol.store.ISVNItem;
import ac.svn.accesscontrol.store.SVNUser;
import ac.svn.accesscontrol.store.UserDetails;
import ac.svn.accesscontrol.store.validator.UserOperationValidator;
import ac.svn.accesscontrol.store.validator.ValidationResult;
import ac.svn.accesscontrol.ui.IUIConstants;
import ac.svn.accesscontrol.ui.MarginBorder;
import ac.svn.accesscontrol.ui.XTextPane;
import ac.svn.accesscontrol.ui.helper.AccessRightsLister;
import ac.svn.accesscontrol.ui.helper.ContentLister;
import ac.svn.accesscontrol.ui.helper.formatter.UserWithGroupTextFormatter;
import ac.svn.accesscontrol.ui.model.ThreadedListModel;
import ac.svn.accesscontrol.ui.renderer.SimpleIconRenderer;
import ac.svn.accesscontrol.ui.window.UserInformationEditorWindow;
import ac.svn.accesscontrol.utils.UIUtility;
import ac.svn.accesscontrol.utils.Utility;

public class UserInformationManager implements INotificationListener,
ISVNIdentifier,
IContextConstants,
IUIConstants,
IConstants
{
	private static String DETAILS_HEADER_CONTENTS 			= "User's Details";
	private static String DETAILS_PANEL_CONTENTS 			= "User's details will be displayed here." +
			"\n1. Select user for listing Contact, Group and Location access related details." +
			"\n2. Select a user and choose action to perform from toolbar on left side of window.";

	private UserInformationEditorWindow informationEditor;

	private SVNUser svnUser;
	private JLabel statusLabel;
	private SVNInfoManager infoManager;
	private Context  context;
	private ContentLister usersLister;

	private AccessRightsLister accessRightsLister;
	private XTextPane xTextPane;
	private JScrollPane scrollPane;
	private JLabel headerLabel;

	private UserInfoEditorStatusController infoEditorStatusController;
	private UserLocationAccessController locationAccessController;
	private UserGroupMembershipController groupMembershipController;
	private UserContactInformationController contactInformationController;

	private UserOperationValidator validator;

	/**
	 * Default constructor of class
	 * */
	public UserInformationManager() 
	{
		informationEditor = new UserInformationEditorWindow();
		xTextPane 				= new XTextPane();
		scrollPane				= new JScrollPane(xTextPane);
		scrollPane.setBackground(Color.WHITE);
		scrollPane.setBorder(UIUtility.setAllShadowedBorder(null));

		Font font = new Font("Tahoma",Font.BOLD , 16);
		headerLabel			= new JLabel("User Details",Utility.getImageIcon(IResources.LOC_ICN_USER_DETAILS_S),JLabel.LEADING);
		headerLabel.setFont(font);

		JPanel pnl  				= new JPanel(new FlowLayout(FlowLayout.LEFT), true);
		pnl.setBackground(Color.WHITE);
		pnl.setBorder(UIUtility.setAllShadowedBorder(null));
		pnl.add(headerLabel);

		scrollPane.setColumnHeaderView(pnl);

		accessRightsLister = new AccessRightsLister(xTextPane);
		accessRightsLister.setClearRequired(true);
		accessRightsLister.setMembershipLabel(headerLabel);

		informationEditor.setIconImage(Utility.getImage(IResources.LOC_ICN_USER_SMALL));


		//Create a context for information editing purposes.
		String contextId = ContextHandler.createContext("UserInformationEditingContext");
		context = ContextHandler.getContext(contextId);

		//Create Location Access Controller.
		locationAccessController = new UserLocationAccessController(informationEditor, informationEditor.getBasicInfoEditorPanel()); 
		locationAccessController.setContext(context);

		//Create group membership controller
		groupMembershipController = new UserGroupMembershipController(informationEditor.getBasicInfoEditorPanel());
		groupMembershipController.setContext(context);		

		//Create user contact information controller
		contactInformationController = new UserContactInformationController(informationEditor.getBasicInfoEditorPanel());
		contactInformationController.setContext(context);

		//Create status handler.
		infoEditorStatusController = new UserInfoEditorStatusController();

		//Create lister for users list on main window.
		ThreadedListModel usersListModel = new ThreadedListModel();
		SimpleIconRenderer iconRenderer = new SimpleIconRenderer(IResources.LOC_ICN_ADD_USER_SMALL);
		iconRenderer.setDefBorder(new MarginBorder());
		iconRenderer.setTextFormatter(new UserWithGroupTextFormatter());

		informationEditor.getUserListView().setModel(usersListModel);
		informationEditor.getUserListView().setCellRenderer(iconRenderer);

		usersLister = new ContentLister(informationEditor.getUserListView(), usersListModel, null);
		usersLister.setListClrRequired(true);
		ListingController.getListingController().registerListerForNotifications(usersLister, ListingController.USER);

		statusLabel = new JLabel("Welcome to User Inforamation Manager");
		statusLabel.setFont(new Font("Tahoma",Font.BOLD,14));

		informationEditor.getStatusPanel().add(statusLabel);
		infoEditorStatusController.setStatusLabel(statusLabel);


		Utility.addEscapeListener(informationEditor);
		NotificationRegistrar.registerListener(this);
		registerListeners();

		infoManager = SVNInfoManager.getInfoManager();

		//Create an instance of Validator.
		validator = new UserOperationValidator();
	}

	/**
	 * Method is responsible for adding listeners to various controls.
	 * */
	private void registerListeners() 
	{

		UIUtility.addPopupListener(informationEditor.getUserListView(), IConstants.VALUE_POPUP_TYPE_USER);

		/***
		 * 
		 */

		informationEditor.getUserListView().addListSelectionListener(new ListSelectionListener() {

			@Override
			public void valueChanged(ListSelectionEvent lse) 
			{
				if(false == lse.getValueIsAdjusting())
				{
					listUserDetails();
				}
			}
		});

		/**
		 * Listener for mouse clock event on User's List.
		 */
		informationEditor.getUserListView().addMouseListener(new MouseAdapter() 
		{
			@Override
			public void mouseClicked(MouseEvent e) 
			{
				super.mouseClicked(e);
				//listUserDetails();
			}
		});

		//Event to handle Finish Button press on "User Information Dialog".
		informationEditor.getBtnFinish().addActionListener(new ActionListener() 
		{
			@Override
			public void actionPerformed(ActionEvent arg0) 
			{
				finishCommandHandler();
			}
		});

		informationEditor.addWindowListener(new WindowAdapter() 
		{
			@Override
			public void windowClosing(WindowEvent e) 
			{
				windowCloseHandler();
				super.windowClosing(e);
			}
		}) ;

		/***
		 * Listener for Buttons
		 */
		UserOperations actionListener = new UserOperations(CMD_CREATE_NEW_USER, informationEditor.getUserListView());
		actionListener.setContext(context);
		informationEditor.getAddUserButton().addActionListener(actionListener);
		informationEditor.getAddUserMI().addActionListener(actionListener);

		actionListener = new UserOperations(CMD_DELETE_USER, informationEditor.getUserListView());
		actionListener.setContext(context);
		informationEditor.getDeleteUserButton().addActionListener(actionListener);
		informationEditor.getRemoveUserMI().addActionListener(actionListener);

		actionListener = new UserOperations(CMD_EDIT_USER, informationEditor.getUserListView());
		actionListener.setContext(context);
		informationEditor.getEditUserButton().addActionListener(actionListener);
		informationEditor.getEditUserMI().addActionListener(actionListener);

		informationEditor.getCloseMI().addActionListener(new ActionListener() 
		{
			@Override
			public void actionPerformed(ActionEvent arg0) 
			{
				windowCloseHandler();
				informationEditor.setVisible(false);
			}
		});
	}

	@Override
	public Set<String> declaredSubscriptionSet() 
	{
		Set<String> subscriptionSet = new HashSet<String>();
		subscriptionSet.add(CMD_SHOW_USER_INFO_MGR);
		subscriptionSet.add(CMD_CREATE_NEW_USER);
		subscriptionSet.add(CMD_EDIT_USER);
		subscriptionSet.add(CMD_DELETE_USER);
		subscriptionSet.add(N_UIM_GROUP_MEM_UPDATE);
		subscriptionSet.add(N_UIM_SYNC_USER_INFO);
		subscriptionSet.add(N_USER_REMOVED);
		return subscriptionSet;
	}

	@Override
	public void receiveEvent(NotificationEvent ne) 
	{
		try
		{
			if (ne.getPropertyIdentifier().contains(CMD_SHOW_USER_INFO_MGR)) 
			{
				//Call method that handles show user command.
				showUserHandler(ne);
			} 
			else if (ne.getPropertyIdentifier().contains(CMD_CREATE_NEW_USER)) 
			{
				//Call method that handles Create New user command.		
				createUserHandler(ne);
			} 
			else if (ne.getPropertyIdentifier().contains(CMD_EDIT_USER)) 
			{
				//Call a method that handles Edit User command.
				editUserHandler(ne);
			}
			else if (ne.getPropertyIdentifier().contains(CMD_DELETE_USER)) 
			{
				deleteUserHandler(ne);
			}
			else if (ne.getPropertyIdentifier().contains(N_UIM_GROUP_MEM_UPDATE)) 
			{
				//			loadUserInformation();
			}
			else if (ne.getPropertyIdentifier().contains(N_UIM_SYNC_USER_INFO)) 
			{
				updateUserInformation();
			}
			else if (ne.getPropertyIdentifier().contains(N_USER_REMOVED)) 
			{
				showDeleteNotification();
			}
		} 
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}

	private void showDeleteNotification() 
	{
		SwingUtilities.invokeLater(new Runnable() {
			@Override
			public void run() 
			{
				String message = "User has been deleted successfully!";
				statusLabel.setIcon(Utility.getImageIcon(IResources.LOC_ICN_DONE));
				statusLabel.setText(message);
				JOptionPane.showMessageDialog(informationEditor, message,"Operation Completed",JOptionPane.INFORMATION_MESSAGE);	
			}
		});
	}

	private void windowCloseHandler()
	{
		if((null != context) && (true == context.isModified()))
		{
			//Get operation state in Context.
			Integer sOp 	= (Integer)context.get(KEY_OPERATION_STATE);
			Integer sType 	= (Integer)context.get(KEY_OPERATION_TYPE);
			//Return if sufficient information is not available for processing.
			if(null == sOp)
			{
				return;
			}

			//Return if operation type is not defined.
			if(null == sType)
			{
				return;
			}
			else
			{
				//If case of delete operation also context change checking is by passed.
				if((VALUE_OP_TYPE_DELETION == sType.intValue()))
				{
					return;
				}
			}

			//Get user details if present
			SVNUser newDetails = (SVNUser) context.get(KEY_OPERATION_PARAM);
			SVNUser oldDetails = (SVNUser) context.get(KEY_OPERATION_PARAM_ORG);

			boolean modificationMade = validator.checkModifications(oldDetails, newDetails);

			if(true == modificationMade)
			{
				String message = "You are currently performing an operation which is not saved, by closing you'll loose changes made. Save changes?";
				String title   = "Pending Change!";

				//Show Dialog asking user to save pending changes.
				int selOption 	= JOptionPane.showConfirmDialog(informationEditor, message,title,JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE);

				//If user wants to save changes.
				if(JOptionPane.YES_OPTION == selOption)
				{
					//Check if modification have been made to user's details.
					finishCommandHandler();
				}

				//Complete operation and clear the context.
				context.clear();
				context.put(KEY_OPERATION_TYPE, VALUE_OP_TYPE_UNDEFINED);
			}
		}		
	}

	private void finishCommandHandler()
	{
		ValidationResult validationResult = validator.validateObject(context);

		if(true == validationResult.isValid())
		{
			//Get current operation being performed 
			int operationType =  ((Integer)context.get(IContextConstants.KEY_OPERATION_TYPE)).intValue();

			if(VALUE_OP_TYPE_UNDEFINED != operationType)
			{
				//Get Latest copy of user object from context.
				SVNUser sUser = (SVNUser) context.get(IContextConstants.KEY_OPERATION_PARAM);

				//Get latest values from UI and update in dictionary.
				UserDetails userDetails = informationEditor.getBasicInfoEditorPanel().getUserDetails();

				updateUserInformation(sUser, userDetails);		

				context.put(KEY_OPERATION_STATE, VALUE_OP_STATE_COMPLETED);
				//Update Information about operation status.
				Utility.sendNotification(N_USER_OPERATION_STATUS,context.clone());

				//Reset Context.
				updateContext(null, VALUE_OP_TYPE_UNDEFINED , VALUE_OP_STATE_COMPLETED, VALUE_TAB_CONTACT_INFO);

				//Reset UI for new operations.
				prepareUIForOperation();
				informationEditor.resetData();		
				accessRightsLister.listAccessRights(svnUser.getId());
			}
			else
			{
				String message = "Cannot complete, no operation defined in context!";
				String title = "No Operation";
				JOptionPane.showMessageDialog(informationEditor,message ,title,JOptionPane.WARNING_MESSAGE);
			}
			context.setModified(false);
			showInfoPane();
		}
		else
		{
			String message = validator.formatMessage("Error occurred while performing operation", validationResult);
			JOptionPane.showMessageDialog(informationEditor, message, "Operation falied!", JOptionPane.ERROR_MESSAGE);
		}


	}

	/***
	 * Method updates modified/added user to SVNInformation Manager and Also update UI.
	 * @param user
	 * @param userDetails
	 */
	private void updateUserInformation(SVNUser sUser,UserDetails userDetails)
	{
		Dictionary.getDictionary().updateUserDetails(userDetails);

		//Update name and userid field with latest values;
		sUser.setUserAlias(userDetails.getUserId());
		sUser.setUserName(userDetails.getUserName());

		infoManager.updateUser(sUser);

		//Update latest information on other UI components.
		updateUserInformation();
	}



	/***
	 * Method Handles Operation related to Delete Button pressed.
	 * @param ne
	 */
	private void deleteUserHandler(NotificationEvent ne)
	{
		//Handle command to delete a user from SubVersion.
		svnUser = (SVNUser) ne.getPropertyValue();

		//Show details of user.
		showInfoPane();
		//accessRightsLister.listAccessRights(svnUser.getId());

		updateContext(svnUser, VALUE_OP_TYPE_DELETION, VALUE_OP_STATE_INPROGRESS, VALUE_TAB_CONTACT_INFO);
		Utility.sendNotification(N_USER_OPERATION_STATUS,context);

		//Mark Context not modified.
		context.setModified(false);

		deleteUser(svnUser);
	}


	/***
	 * Method that handles ShowUser command and related processing.
	 * @param ne
	 */
	private void showUserHandler(NotificationEvent ne)
	{
		//Show information Panel
		showInfoPane();

		// Handle command received for showing User information manager.
		svnUser = null;
		updateContext(null, VALUE_OP_TYPE_UNDEFINED, VALUE_OP_STATE_UNDEFINED, VALUE_TAB_CONTACT_INFO);
		showEditorDialog(false);
	}
	/***
	 * 	Method handles Edit user command.
	 * @param ne
	 */
	private void editUserHandler(NotificationEvent ne) 
	{
		//Handle command received for modifying existing user in system.
		svnUser = (SVNUser) ne.getPropertyValue();
		if(null != svnUser)
		{
			updateContext(svnUser, VALUE_OP_TYPE_EDITING, VALUE_OP_STATE_INPROGRESS, VALUE_TAB_CONTACT_INFO);

			context.put(KEY_OPERATION_PARAM_ORG, svnUser.clone());
			context.put(KEY_OPERATION_PARAM, svnUser);

			loadUserInformation();
			Utility.sendNotification(N_USER_OPERATION_STATUS,context);

			//Mark Context not modified.
			context.setModified(false);

			showEditorPane();
		}
	}

	/***
	 * Method that handle create a new user command.
	 * @param ne
	 */
	private void createUserHandler(NotificationEvent ne) 
	{
		//Show Editing panel
		showEditorPane();
		//Handle command received for adding a new user to system.
		svnUser = new SVNUser("New User", "NewUser");
		updateContext(svnUser, VALUE_OP_TYPE_ADDITION, VALUE_OP_STATE_INPROGRESS, VALUE_TAB_CONTACT_INFO);
		showEditorDialog(false);
		loadUserInformation();
		Utility.sendNotification(N_USER_OPERATION_STATUS,context);
		//Mark Context not modified.
		context.setModified(false);
	}


	private void updateContext(Object parameter,int opType,int opState,int tabVisible)
	{
		if(null != context )
		{
			context.put(IContextConstants.KEY_OPERATION_PARAM,parameter);
			context.put(IContextConstants.KEY_OPERATION_TYPE, opType);
			context.put(IContextConstants.KEY_OPERATION_STATE,opState);
			context.put(IContextConstants.KEY_CURRENT_TAB,tabVisible);
		}
	}

	/***
	 * Method sends notification to Controller responsible for managing and displaying user's location access related information.
	 */
	private void loadUserLocationDetails() 
	{
		context.put(IContextConstants.KEY_OPERATION_PARAM, svnUser);
		Utility.sendNotification(CMD_SHOW_USER_ACCESS_RIGHT);		
	}

	private void deleteUser(final ISVNItem user) 
	{
		if(user instanceof SVNUser)
		{
			SwingUtilities.invokeLater(new Runnable() {
				@Override
				public void run() {
					SVNUser svnUser = (SVNUser) user; 
					int selOp = JOptionPane.showConfirmDialog(informationEditor,
							String.format("This will delete user \"%s\" from SVN, continue with deletion?",svnUser.getName()),
							"Delete User?",
							JOptionPane.YES_NO_OPTION,
							JOptionPane.QUESTION_MESSAGE);	
					if(JOptionPane.YES_OPTION == selOp)
					{
						Utility.sendNotification(CMD_DELETE_ENTITY,svnUser);
					}
					else
					{
						sendStatusUpdateMessage(MESSAGE_TYPE_ERROR, "Delete operation cancelled!");
					}
				}
			});
		}
	}

	/***
	 * Method sends notification to Controller responsible for managing and displaying user's contact information. 
	 * @param argSvnUser
	 */
	private void loadUserAccountDetails(SVNUser argSvnUser) 
	{
		context.put(IContextConstants.KEY_OPERATION_PARAM, argSvnUser);
		Utility.sendNotification(CMD_SHOW_USER_CONTACT_INFO);
	}

	/***
	 * Method sends notification to Controller responsible for managing and displaying user's group information.
	 */
	private void loadUserGroupDetails() 
	{
		//TODO Send command to GroupMembership Controller to update users groups related details.
		context.put(IContextConstants.KEY_OPERATION_PARAM, svnUser);
		Utility.sendNotification(CMD_SHOW_USER_GROUP_MEMSHIP);
	}

	private void showEditorDialog(boolean editMode) 
	{
		prepareUIForOperation();
		informationEditor.resetData();

		if(false == informationEditor.isVisible())
		{
			SwingUtilities.invokeLater(new Runnable() {
				@Override
				public void run() {
					usersLister.listItems(infoManager.getAllUsers());
					informationEditor.setExtendedState(JFrame.MAXIMIZED_BOTH);
					informationEditor.setVisible(true);
					informationEditor.toFront();
					//informationEditor.repaint();
				}
			});
		}

	}

	protected synchronized void updateUserInformation() 
	{
		try
		{
			Dictionary dictionary = Dictionary.getDictionary();
			for (String userId : dictionary.getUserDetails().keySet()) 
			{
				UserDetails details = dictionary.getUserDetails(userId);
				SVNUser svnUser = infoManager.getSvnUser(userId);
				//Check if user is only added in this software and not in SVN config file.
				if(null != svnUser)
				{
					svnUser.setUserName(details.getUserName());
					infoManager.updateUser(svnUser);
				}
			}

			Utility.sendNotification(N_UPDATE_LISTINGS,IUIConstants.C_LIST_TYPE_USER);
			Utility.sendNotification(N_UPDATE_LISTINGS,IUIConstants.C_LIST_TYPE_GROUP);
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}

	private void loadUserInformation() 
	{
		svnUser = (SVNUser) context.get(IContextConstants.KEY_OPERATION_PARAM);
		if(null != svnUser)
		{
			showEditorDialog(true);
			loadUserAccountDetails(svnUser);
			loadUserGroupDetails();
			loadUserLocationDetails();
		}
		else
		{
			System.err.println("Unable to find user's information in UserInformationManager.loadInfomation method.");
		}
	}

	private void showEditorPane()
	{
		informationEditor.setCenterView(informationEditor.getBasicInfoEditorPanel(),scrollPane);
	}

	private void showInfoPane()
	{
		informationEditor.setCenterView(scrollPane,informationEditor.getBasicInfoEditorPanel());
		xTextPane.setText(DETAILS_PANEL_CONTENTS);
		accessRightsLister.showStatusText(DETAILS_HEADER_CONTENTS);
		//sendStatusUpdateMessage(MESSAGE_TYPE_INFORMATION, OPERATION_STATUS_CONTENTS);
	}

	class UserOperations implements ActionListener
	{
		private String messageId;
		private JList sourceComponent;
		private Context context;

		public UserOperations(String messageId,JList sourceComponent)
		{
			this.messageId = messageId;
			this.sourceComponent = sourceComponent;
		}

		@Override
		public void actionPerformed(ActionEvent ae) 
		{
			try
			{
				//showEditorPane();
				ISVNItem selObject = (ISVNItem) sourceComponent.getSelectedValue();
				context.put(KEY_OPERATION_PARAM, selObject);
				Utility.sendNotification(messageId,selObject);

			}
			catch(Exception e)
			{
				System.err.println("Error occurred while sending event: " + messageId);
				e.printStackTrace();
			}
		}


		/**
		 * @param context the context to set
		 */
		public void setContext(Context context) 
		{
			this.context = context;
		}
	}

	/***
	 * Method makes necessary changes in UI to make it adaptable for current operation in context.
	 */
	private void prepareUIForOperation() 
	{
		//Context is not available.
		if(null != context)
		{
			//Check operation type to be performed.
			int opType = (Integer) context.get(KEY_OPERATION_TYPE);
			switch (opType) 
			{
			//Do needful UI changes for Addition.
			case VALUE_OP_TYPE_ADDITION:
				informationEditor.getUserListView().clearSelection();
				setButtonState(true);
				informationEditor.getBasicInfoEditorPanel().getTextSVNUserId().setEditable(true);
				informationEditor.getBasicInfoEditorPanel().getTextSVNUserId().setFocusable(true);
				break;
				//Do needful UI changes for Edit Operation.
			case VALUE_OP_TYPE_EDITING:
				setButtonState(true);
				informationEditor.getBasicInfoEditorPanel().getTextSVNUserId().setEditable(false);
				informationEditor.getBasicInfoEditorPanel().getTextSVNUserId().setFocusable(false);
				break;
				//Do needful UI changes for Deletion.
			case VALUE_OP_TYPE_DELETION:
				setButtonState(false);
				break;
				//Do needful UI changes for rest of the operation..	
			case VALUE_OP_TYPE_UNDEFINED:	
			default:
				setButtonState(false);
				break;
			}
		}
	}

	/***
	 * 
	 */
	private void setButtonState(boolean f)
	{
		informationEditor.getBtnFinish().setEnabled(f);
	}



	private void listUserDetails()
	{
		SVNUser svnUser = 	(SVNUser) informationEditor.getUserListView().getSelectedValue();;
		if(null != svnUser)
		{
			String text = String.format("User: %s  Alias:%s  Groups: %s",svnUser.getName(),svnUser.getUserAlias(),svnUser.getGroups().toString());
			sendStatusUpdateMessage(MESSAGE_TYPE_INFORMATION, text);

			//Set Access Lister as main component of User Information Manager.
			informationEditor.setCenterView(scrollPane,informationEditor.getBasicInfoEditorPanel());
			accessRightsLister.listAccessRights(svnUser.getId());
		}
	}


	private void sendStatusUpdateMessage(int messageType,String message)
	{
		NotificationEvent event = new NotificationEvent(N_GENERAL_MESSAGE_DISPLAY);
		event.setPropertyValue(message);
		event.addParameter(KEY_MESSAGE_TYPE, messageType);
		NotificationRegistrar.dispatchNotification(event);
	}

}